package com.example.homelicaisystem.services.impl;

import com.example.homelicaisystem.dao.ExpendDetailMapper;
import com.example.homelicaisystem.entity.ExpendDetail;
import com.example.homelicaisystem.entity.DTO.ExpendDetailDTO;
import com.example.homelicaisystem.entity.SelectResult;
import com.example.homelicaisystem.services.ExpendDetailService;
import com.example.homelicaisystem.utils.UserUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ExpendDetailImpl implements ExpendDetailService {
private final ExpendDetailMapper expendDetailMapper;

    public ExpendDetailImpl(ExpendDetailMapper expendDetailMapper) {
        this.expendDetailMapper = expendDetailMapper;
    }


    @Override
    public Page<ExpendDetail> getList(ExpendDetailDTO data) {

        PageHelper.startPage(data.getPageNum(), data.getPageSize());
        return expendDetailMapper.getList(data);
    }

    @Override
    public void delete(int id) {

        expendDetailMapper.delete(id);
    }

    @Override
    public void modify(ExpendDetail data) {
        expendDetailMapper.update(data);
    }

    @Override
    public ExpendDetail create(ExpendDetail data) {
        //记录创建时间
        data.setDate(new Date());
        //把id传给data
        data.setUserId(UserUtil.getUserId());
        //数据库添加数据
        expendDetailMapper.insertExpendDetail(data);
        return data;
    }

    @Override
    public List<SelectResult> selectExpendType() {
        return expendDetailMapper.selectExpendType();

    }

    @Override
    public List<SelectResult> selectExpendMode() {
        return expendDetailMapper.selectExpendMode();
    }

    @Override
    public ExpendDetail getExpendDetailById(Integer id) {
        return expendDetailMapper.getExpendDetailById(id);
    }
}
